package com.mi9688.stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class LimitSkip {
    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5,6,7,8,9,10);
        // 获取前3个元素
        Stream<Integer> limitedStream = numbers.stream().limit(3);

        limitedStream.forEach(System.out::println);

        System.out.println("-----------------------------------------------");
        //跳过前两个元素
        Stream<Integer> skipStream = numbers.stream().skip(2);
        skipStream.forEach(System.out::println);

        System.out.println("-----------------------------------------------");
        //一页五个截取第二页
        Stream<Integer> skipLimitStream = numbers.stream().skip(5).limit(5);
        skipLimitStream.forEach(System.out::println);
    }
}
